package com.wdb007.venus.wss.service.impl;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wdb007.venus.svc.facade.BookgridService;
import com.wdb007.venus.wss.channelgroup.BookCaseChannelGroups;
import com.wdb007.venus.wss.service.WebSocketServerService;

import io.netty.channel.ChannelHandlerContext;

@Service("bookCaseStatusFixedResService")
public class BookCaseStatusFixedResService implements WebSocketServerService {
	private static Logger logger = LoggerFactory.getLogger(BookCaseStatusFixedResService.class);
	@Autowired
	private BookgridService bookgridService;
	@Override
	public String doService(ChannelHandlerContext ctx, String request) throws Exception {
		JSONObject jsonObj = JSON.parseObject(request);
		logger.info("BookCaseStatusFixed 接收websocket响应信息: {}", jsonObj.toJSONString());
		try {
			Map<String, String> statuses = (Map<String, String>) jsonObj.get("statuses");
			String bookcaseId = BookCaseChannelGroups.getBookCaseId(ctx.channel());
			logger.info("debug {} : 书柜[{}],响应内容[{}]", jsonObj.getString("action"), bookcaseId, jsonObj.toJSONString());
			bookgridService.bookCaseStatusReport(statuses);
		} catch (Exception e) {
			logger.error("整书柜状态上报(定时)异常", e);
		}
		return null;
	}

}
